package com.jxt.myjxtmanager.views;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.WindowManager.LayoutParams;
import android.widget.ListView;

import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.adapter.DialogSelectAdapter;
import com.jxt.myjxtmanager.utils.SystemInfo;

import java.util.List;


public class CustomSelectDialog extends AlertDialog {

    Context mContext;
    List<String> mData;
    OnClickCityItem instance;

    public CustomSelectDialog(Context context, List<String> data, CustomSelectDialog.OnClickCityItem instance) {
        super(context);
        mContext = context;
        this.mData = data;
        this.instance = instance;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        DisplayMetrics display = SystemInfo.getDeviceDisplayMetrics(this
                .getContext());
        LayoutParams lp = this.getWindow().getAttributes();
        lp.width = display.widthPixels - display.widthPixels / 5;
        if (mData != null && mData.size() > 8) {
            lp.height = display.heightPixels / 2;
        } else {
            lp.height = LayoutParams.WRAP_CONTENT;
        }
        this.getWindow().setAttributes(lp);
        setContentView(R.layout.dialog_select_custom);
        initView(instance);
    }


    private void initView(OnClickCityItem instance) {
        ListView list = (ListView) findViewById(R.id.list_dialog_select_city);
        DialogSelectAdapter adapter = new DialogSelectAdapter(mContext,  mData);
        adapter.setOnClickInstance(instance);
        list.setAdapter(adapter);
    }

    /***
     * 点击事件回调
     *
     * @author lkk
     */
    public interface OnClickCityItem {
        void onItemClick(int position);
    }
}
